package com.example.rxjavautildemo.fragment.rxbus;

import android.view.View;

import com.example.rxjavautildemo.R;
import com.example.rxjavautildemo.base.BaseFragment;
import com.example.rxjavautildemo.entity.Event;
import com.example.rxjavautildemo.entity.EventKey;
import com.xuexiang.rxutil2.rxbus.RxBusUtils;
import com.xuexiang.xutil.system.AppExecutors;

import butterknife.OnClick;

public class RxBusControlFragment extends BaseFragment {
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_rxbus_control;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initListener() {

    }

    @OnClick({R.id.btn_send_data,R.id.btn_send_nodata,R.id.btn_one_by_one,
            R.id.btn_one_by_more,R.id.btn_back_mainthread,R.id.btn_back_normal})
    protected void onViewClicked(View view){
        switch (view.getId()) {
            case R.id.btn_send_data:
                RxBusUtils.get().post(EventKey.EVENT_HAVE_DATA,new Event(EventKey.EVENT_HAVE_DATA,"这里携带的是数据"));
                break;
            case R.id.btn_send_nodata:
                RxBusUtils.get().postRxEvent(EventKey.EVENT_NO_DATA);
                break;
            case R.id.btn_one_by_one:
                RxBusUtils.get().post(EventKey.EVENT_ONE_BY_ONE);
                break;
            case R.id.btn_one_by_more:
                RxBusUtils.get().post(EventKey.EVENT_ONE_BY_MORE);
                break;
            case R.id.btn_back_mainthread:
                AppExecutors.get().poolIO().execute(new Runnable() {
                    @Override
                    public void run() {
                        RxBusUtils.get().post(EventKey.EVENT_BACK_MAINTHREAD);
                    }
                });
                break;
            case R.id.btn_back_normal:
                AppExecutors.get().poolIO().execute(new Runnable() {
                    @Override
                    public void run() {
                        RxBusUtils.get().post(EventKey.EVENT_BACK_NORMAL);
                    }
                });
                break;
            case R.id.btn_clear_all:
                RxBusUtils.get().post(EventKey.EVENT_CLEAR);
                break;
            default:
                break;
        }

    }
}
